﻿<?php

	$i = isset($_GET['i']) && $_GET['i'] !="" ? $_GET['i'] : -1;
	if ( $i===-1 ){
		Utils::redirect("preferences");
	}
	
	$b = $_SESSION['selection'][ $i ];

	echo Utils::breadCrumbs(array(
							array('label' => 'My beverage list', 'link' => 'preferences'), 
							array('label'=> 'Edit selection "'.$b['name'].'"')
						));

if ( isset($_POST['submit-update']) ) : 

	$_SESSION['selection'][$i]['size'] = $_POST['size'];
	if ( isset($_POST['sugar']) ){
		$_SESSION['selection'][$i]['sugar'] = $_POST['sugar'];
	}
	Utils::redirect('preferences');

else: ?>

<form style="text-align:center; width:340px;" method="post" action="index.php?p=editselection&i=<?php echo @$_GET['i']; ?>">
	<h2>Editing your beverage "<?php echo $b['name']; ?>": </h2>
	<p style="text-align:center;">
		<img src="<?php echo $b['image_src']; ?>" alt="<?php echo $b['image_alt']; ?>" />
	</p>
	<br/>
	<label for="size">Cup size</label>
	<select name="size">
		<option value="small" <?php echo $b['size']==='small'?'selected':'';  ?> >Small</option>
		<option value="medium" <?php echo $b['size']==='medium'?'selected':'';  ?> >Medium</option>
		<option value="large" <?php echo $b['size']==='large'?'selected':'';  ?> >Large</option>
	</select>
	<br/>
	
	<?php
		if ( isset($b['sugar']) && $b['sugar']!=="" ):
	?>
	<label for="sugar">The amout of sugar</label>
	<select name="sugar">
		<option value="0" selected="selected">None</option>
		<option value="1" >Half</option>
		<option value="2" >One</option>
		<option value="3" >Two</option>
		<option value="4" >Four</option>
	</select>
	<?php
		endif;
	?>
	
	<br />
	<br />
	<p class="button_container">
		<img src="img/icons/cancel.png" class="button_icon"/><a class="button red" href="index.php?p=preferences" title="Cancel" >Cancel</a>
		<img src="img/icons/ok.png" class="button_icon"/><input class="button green" type="submit" name="submit-update" value="Update my selection" />
	</p>

</form>

<?php endif; ?>
